package awaywalk.run
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import away3d.containers.ObjectContainer3D;
	import away3d.containers.View3D;
	
	import awaywalk.camera.WCamera;
	
	/**
	 * 启动Away3D场景，相机以及3D物体
	 * @author mengtianwxs
	 * @createTime 2013-6-27
	 */
	
	public class AwayWalk extends EventDispatcher
	{
		/*@stage*/
		private var _stage:Stage;
		/*@View3D*/
		private  var _view:View3D;
		
		/**
		 * Engine构造函数 
		 * 
		 */		
		public function AwayWalk()
		{
			
			
		}
		
		/**
		 * 配置Away3D
		 * @param stage
		 * @param frameRate
		 * @param url
		 * 
		 */	    
		public  function configuration(stage:Stage=null,frameRate:Number=60,url:String=null):void
		{
			_stage=stage;
			_stage.frameRate=frameRate;
			
			_view.addSourceURL(url);
			
		}
		
		/**
		 * 初始化Away3D 
		 * @param camera
		 * @param forceSoftware
		 * 
		 */		
		public  function initialize(camera:WCamera=null,forceSoftware:Boolean=false):void
		{
			_view=new View3D(null,camera,null,forceSoftware);
			
			
			_stage.addChild(_view);
			
			
		}
		
		/**
		 * 开始渲染 
		 * 
		 */		
		
		public function start():void
		{
			addEventListener(Event.ENTER_FRAME,update);
		}
		
		/**
		 * 更新场景
		 * @param event
		 * 
		 */
		protected function update(event:Event):void
		{
			// TODO Auto-generated method stub
			_view.render();
		
		}
		
		/**
		 *添加3D物体 
		 * @param objectContainer3D
		 * 
		 */		
		public function add(objectContainer3D:ObjectContainer3D=null):void
		{
			_view.scene.addChild(objectContainer3D);
		}
		
		/**
		 * 释放场景所占用的资源 
		 * 
		 */		
		public function dispose():void
		{
			_view.dispose();
		}
	}
}